# coding=utf-8

"""
理解slim.softmax()对4-D tensor的计算过程: 对应到卷积feature maps上,是
在feature map的每个pixel上，对所有batch和channels进行softmax
"""

import math
import tensorflow as tf
import tensorflow.contrib.slim as slim

x = tf.constant([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8], dtype = tf.float32)
x = tf.reshape(x, [1, 2, 2, 2])
y = slim.softmax(x)
# init
init = tf.global_variables_initializer()
def train():
	with tf.Session() as sess:
		sess.run(init)
		a = sess.run(x)
		print a.shape
		print a
		b = sess.run(y)
		print b.shape
		print b
		
		for i in range(0, 2):
			for j in range(0, 2):
				curE = 0.
				for c in range(0, 2):
					curE = curE + math.exp(a[0, i, j, c])
				for c in range(0, 2):
					print i, j, math.exp(a[0, i, j, c]) / curE
			
			
if __name__ == "__main__":
	train()


